package com.bcu.cn.onlineexamsystem.teacherhomemanage.service.impl;

import com.bcu.cn.onlineexamsystem.teacherhomemanage.controller.TeacherHomeDTO;
import com.bcu.cn.onlineexamsystem.teacherhomemanage.mapper.TeacherHomeMapper;
import com.bcu.cn.onlineexamsystem.teacherhomemanage.service.TeacherHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeacherHomeServiceImpl implements TeacherHomeService {
    
    @Autowired
    private TeacherHomeMapper teacherHomeMapper;
    
    @Override
    public TeacherHomeDTO getHomeData(String teacherId) {
        TeacherHomeDTO homeData = new TeacherHomeDTO();
        
        // 获取用户真实姓名
        String realName = teacherHomeMapper.getRealNameByUserId(teacherId);
        homeData.setRealName(realName != null ? realName : "教师");
        
        // 获取教师创建的考试总数
        Integer totalExams = teacherHomeMapper.getTotalExamsCount(teacherId);
        homeData.setTotalExams(totalExams != null ? totalExams : 0);
        
        // 获取题库题目总数
        Integer questionCount = teacherHomeMapper.getQuestionCount();
        homeData.setQuestionCount(questionCount != null ? questionCount : 0);
        
        // 获取待批改考试数量
        Integer pendingExams = teacherHomeMapper.getPendingExamsCount(teacherId);
        homeData.setPendingExams(pendingExams != null ? pendingExams : 0);
        
        // 获取最近创建考试名称
        String latestExamName = teacherHomeMapper.getLatestExamName(teacherId);
        homeData.setLatestExamName(latestExamName != null ? latestExamName : "-");
        
        return homeData;
    }
} 